package org.systm.adminuser.service.condition;

import org.springframework.data.jpa.domain.Specification;
import org.systm.adminuser.entity.UserPermission;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Path;
import java.util.List;
import java.util.function.Function;

public class UserPermissionQuery {
    public final static Function<String, Specification<UserPermission>> perSpec = (per) -> (r, q, cb) -> {
        Expression<String> perEx = r.get("per").as(String.class);
        Expression<Boolean> delEx = r.get("del").as(Boolean.class);
        return cb.and(cb.equal(perEx, per), cb.equal(delEx, Boolean.FALSE));
    };

    public final static Function<List<String>, Specification<UserPermission>> perSpecs = (per) -> (r, q, cb) -> {
        Path<Object> perPath = r.get("per");
        Expression<Boolean> delEx = r.get("del").as(Boolean.class);
        return cb.and(perPath.in(per), cb.equal(delEx, Boolean.FALSE));
    };
}
